// 引入axios
import axios from "axios";
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';

// 创建axios实例
const mockAjax = axios.create({
    baseURL:'/mock',
    timeout: 1000
});

// 设置请求拦截器
mockAjax.interceptors.request.use(config =>{
    // 设置进度条的开始
    NProgress.start();
    return config;
});

// 设置响应拦截器
mockAjax.interceptors.response.use(
    response => {
        // 进度条结束
        NProgress.done();
        return response.data;
    },
    error => {
        NProgress.done();
        return Promise.reject(new Error(error.message))
    }
)

// 导出
export default mockAjax;